package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.AccountSystem;
import com.briup.jz.bean.AccountSystemExample;
import com.briup.jz.bean.AccountSystemExample.Criteria;
import com.briup.jz.dao.AccountSystemMapper;
import com.briup.jz.service.IAccountSystemServicer;
import com.briup.jz.utils.CustomerException;
@Service
public class AccountSystemlmpl implements IAccountSystemServicer{
	@Autowired
private  AccountSystemMapper accountSystemMapper;
	@Override
	public void saveOrUpdate(AccountSystem accountSystem) throws CustomerException {
		// TODO Auto-generated method stub
		if(accountSystem.getId()!=null)
		{
			accountSystemMapper.updateByPrimaryKey(accountSystem);
		}
		accountSystemMapper.insert(accountSystem);
	}

	@Override
	public List<AccountSystem> query(String type,String status) {
		AccountSystemExample example=new AccountSystemExample();
	    AccountSystemExample.Criteria criteria=example.createCriteria();
		if(type!=null)
		{
			criteria.andTypeEqualTo(type);
		}
		if(status!=null)
		{
			criteria.andStatusEqualTo(status);
		}
		List<AccountSystem> list=accountSystemMapper.selectByExample(example);
		return list;
	}

	@Override
	public void deleteById(long id) throws CustomerException {
		// TODO Auto-generated method stub
		AccountSystem accountSystem=accountSystemMapper.selectByPrimaryKey(id);
		if(accountSystem!=null)
		{
			accountSystemMapper.deleteByPrimaryKey(id);
		}
		else {
			throw new CustomerException("要删除的分类信息不存在");
		}
		
	}

}
